package com.spring.service.util;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import com.spring.domain.User;

public class UserMapper implements ParameterizedRowMapper<User> {

    public User mapRow(ResultSet rs, int rowNum) throws SQLException {
        User user = new User();
        user.setId(rs.getInt("id"));
    	user.setMail(rs.getString("mail"));
    	user.setPwd(rs.getString("pwd"));
    	user.setStartDate(rs.getDate("startDate"));
    	user.setActivationCode(rs.getString("activationCode"));
    	user.setNewsLetter(rs.getInt("newsLetter"));
    	user.setAdmin(rs.getInt("admin"));
        return user;
    }
    
    public static MapSqlParameterSource sqlMap (User user){
    	return new MapSqlParameterSource()
				.addValue("mail", user.getMail())
				.addValue("pwd", user.getPwd())
				.addValue("id", user.getId())
				.addValue("startDate", user.getStartDate())
				.addValue("newsLetter", user.getNewsLetter())
				.addValue("activationCode", user.getActivationCode())
				.addValue("admin",user.getAdmin());
    	
    }

}
